﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace biaoqian
{
    public partial class ADDCYDW : Form
    {
        LDhuoyunEntities db = new LDhuoyunEntities();
        Class1 one = new Class1();
        public ADDCYDW()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cy_Name = textBox1.Text;
            int count = db.CYDW.Where(x => x.cy_name == cy_Name).Count();
            int cojuj = db.CYDW.Count();
            cojuj = cojuj + 1;
            if (count > 0)
            {
                MessageBox.Show("改承运单位已存在，不可重复添加");
            }
            else
            {
                CYDW cy = new CYDW()
                {
                    cy_id=cojuj,
                    cy_name=cy_Name
                };
                db.CYDW.Add(cy);
                db.SaveChanges();
                MessageBox.Show("添加成功");
            }
        }
    }
}
